package org.grayrabbit.cms.entity;

// Generated 2011-5-16 13:39:30 by Hibernate Tools 3.3.0.GA

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.grayrabbit.cms.tree.TreeNode;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;


/**
 * CmsCategory generated by hbm2java
 */
@Entity
@Table(name = "CMS_CATEGORY")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Category implements java.io.Serializable,TreeNode{

	private static final long serialVersionUID = 3369239635643669046L;
	/**栏目的生成目录*/
	public static final String CATEGORY_PATH = "category";
	private String categoryId;
	private Site site;
	private Category category;
	private String catName;
	private Boolean isContribute;
	private Boolean isComment;
	private Boolean isInitComment;
	private Boolean isAudit;
	private String auditor;
	private String catIndexTpl;
	private String catContentListTpl;
	private String catSimpleName;
	private String catContentTplSet;
	private String catDefaultContentTpl;
	private String catContentTitleAlert;
	private String catContentPhotoAlert;
	private Integer ord;
	private Date createTime;
	private String createLoginName;
	private String createRealName;
	private Date updateTime;
	private String updateLoginName;
	private String updateRealName;
	private Boolean categoryStatus;
	private Set<Role> roles = new HashSet<Role>(0);
	private Set<Content> contents = new HashSet<Content>(0);
	private Set<Category> categories = new HashSet<Category>(0);
	private List<Category> sons = new ArrayList<Category>(0);
	private Boolean isLink;
	private Boolean treeIndexLink;
	
	//二期
	private Boolean catShare;//是否共享
	private String adPosition;//栏目广告位置（1-顶部，2-左边，3-右边，4-列表中央，5-文章中央，6-底部）、广告形式（1-文字，2-图片，3-视频），例12:顶部图片的形式展示
	private String smallPictureSize; //小图片大小
	private String middlePictureSize;//中图片大小
	private String bigPictureSize;//大图片大小
	private String picType;//图片类型
	private String cartoonType;//动画类型
	private String videoType;//视频类型
	private String softWareType;//软件类型
	private Long pictureAdvice;//图片大小限制
	private Long cartoonAdvice;//动画大小限制
	private Long videoAdvice;//视频大小限制
	private Long softwareAdvice;//软件大小限制
	private Boolean isCatelogNav;// 是否插件导航
	private String catelogNavUrl;//导航Url
	//end
	public Category() {
	}

	public Category(String categoryId) {
		this.categoryId = categoryId;
	}


	@Id
	@Column(name = "CATEGORY_ID", unique = true, nullable = false, length = 32)
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "uuid") 
	public String getCategoryId() {
		return this.categoryId;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SITE_ID")
	public Site getSite() {
		return this.site;
	}

	public void setSite(Site site) {
		this.site = site;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PARENT_ID")
	public Category getCategory() {
		return this.category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	@Column(name = "CAT_NAME", length = 256)
	public String getCatName() {
		return this.catName;
	}

	public void setCatName(String catName) {
		this.catName = catName;
	}

	@Column(name = "IS_CONTRIBUTE", precision = 1, scale = 0)
	public Boolean getIsContribute() {
		return this.isContribute;
	}

	public void setIsContribute(Boolean isContribute) {
		this.isContribute = isContribute;
	}

	@Column(name = "IS_COMMENT", precision = 1, scale = 0)
	public Boolean getIsComment() {
		return this.isComment;
	}

	public void setIsComment(Boolean isComment) {
		this.isComment = isComment;
	}

	@Column(name = "IS_INIT_COMMENT", precision = 1, scale = 0)
	public Boolean getIsInitComment() {
		return this.isInitComment;
	}

	public void setIsInitComment(Boolean isInitComment) {
		this.isInitComment = isInitComment;
	}

	@Column(name = "IS_AUDIT", precision = 1, scale = 0)
	public Boolean getIsAudit() {
		return this.isAudit;
	}

	public void setIsAudit(Boolean isAudit) {
		this.isAudit = isAudit;
	}

	@Column(name = "AUDITOR", length = 256)
	public String getAuditor() {
		return this.auditor;
	}

	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	@Column(name = "CAT_INDEX_TPL", length = 256)
	public String getCatIndexTpl() {
		return this.catIndexTpl;
	}

	public void setCatIndexTpl(String catIndexTpl) {
		this.catIndexTpl = catIndexTpl;
	}

	@Column(name = "CAT_CONTENT_LIST_TPL", length = 256)
	public String getCatContentListTpl() {
		return this.catContentListTpl;
	}

	public void setCatContentListTpl(String catContentListTpl) {
		this.catContentListTpl = catContentListTpl;
	}

	@Column(name = "CAT_SIMPLE_NAME", length = 64)
	public String getCatSimpleName() {
		return this.catSimpleName;
	}

	public void setCatSimpleName(String catSimpleName) {
		this.catSimpleName = catSimpleName;
	}

	@Column(name = "CAT_CONTENT_TPL_SET", length = 4000)
	public String getCatContentTplSet() {
		return this.catContentTplSet;
	}

	public void setCatContentTplSet(String catContentTplSet) {
		this.catContentTplSet = catContentTplSet;
	}

	@Column(name = "CAT_DEFAULT_CONTENT_TPL", length = 256)
	public String getCatDefaultContentTpl() {
		return this.catDefaultContentTpl;
	}

	public void setCatDefaultContentTpl(String catDefaultContentTpl) {
		this.catDefaultContentTpl = catDefaultContentTpl;
	}

	@Column(name = "CAT_CONTENT_TITLE_ALERT", length = 256)
	public String getCatContentTitleAlert() {
		return this.catContentTitleAlert;
	}

	public void setCatContentTitleAlert(String catContentTitleAlert) {
		this.catContentTitleAlert = catContentTitleAlert;
	}

	@Column(name = "CAT_CONTENT_PHOTO_ALERT", length = 256)
	public String getCatContentPhotoAlert() {
		return this.catContentPhotoAlert;
	}

	public void setCatContentPhotoAlert(String catContentPhotoAlert) {
		this.catContentPhotoAlert = catContentPhotoAlert;
	}

	@Column(name = "ORD", precision = 6, scale = 0)
	public Integer getOrd() {
		return this.ord;
	}

	public void setOrd(Integer ord) {
		this.ord = ord;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATE_TIME", length = 7)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "CREATE_LOGIN_NAME", length = 64)
	public String getCreateLoginName() {
		return this.createLoginName;
	}

	public void setCreateLoginName(String createLoginName) {
		this.createLoginName = createLoginName;
	}

	@Column(name = "CREATE_REAL_NAME", length = 64)
	public String getCreateRealName() {
		return this.createRealName;
	}

	public void setCreateRealName(String createRealName) {
		this.createRealName = createRealName;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "UPDATE_TIME", length = 7)
	public Date getUpdateTime() {
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name = "UPDATE_LOGIN_NAME", length = 64)
	public String getUpdateLoginName() {
		return this.updateLoginName;
	}

	public void setUpdateLoginName(String updateLoginName) {
		this.updateLoginName = updateLoginName;
	}

	@Column(name = "UPDATE_REAL_NAME", length = 64)
	public String getUpdateRealName() {
		return this.updateRealName;
	}

	public void setUpdateRealName(String updateRealName) {
		this.updateRealName = updateRealName;
	}
	@Column(name = "CATEGORY_STATUS", precision = 1, scale = 0)
	public Boolean getCategoryStatus() {
		return categoryStatus;
	}

	public void setCategoryStatus(Boolean categoryStatus) {
		this.categoryStatus = categoryStatus;
	}

	@Column(name = "IS_LINK", precision = 1, scale = 0)
	public Boolean getIsLink() {
		return isLink;
	}

	public void setIsLink(Boolean isLink) {
		this.isLink = isLink;
	}
	@Column(name = "TREE_INDEX_LINK", precision = 1, scale = 0)
	public Boolean getTreeIndexLink() {
		return treeIndexLink;
	}

	public void setTreeIndexLink(Boolean treeIndexLink) {
		this.treeIndexLink = treeIndexLink;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "CMS_ROLE_CAT_RELA", joinColumns = { @JoinColumn(name = "CATEGORY_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) })
	public Set<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "category")
	public Set<Content> getContents() {
		return this.contents;
	}

	public void setContents(Set<Content> contents) {
		this.contents = contents;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "category") 
	@org.hibernate.annotations.OrderBy(clause="ord asc,cat_name asc")
	public Set<Category> getCategories() {
		return this.categories;
	}

	public void setCategories(Set<Category> categories) {
		this.categories = categories;
	}

	@Transient
	public String getTreeNodeId() {
		return categoryId;
	}

	@Transient
	public String getTreeNodeName() {
		String url = "category-list.action?category.categoryId="+categoryId;
		return "<a href='"+url+"' target='mainframe'>"+catName+"</a>";
	}

	@Transient
	public String getTreeNodeNameDoc() {
		String url = "../content/content-list.action?content.category.categoryId="+categoryId;
		return  "<a href='"+url+"' target='mainframe'>"+catName+"</a>";
	}

	@Transient
	public String getTreeNodeNameBox() {
		String boxInfo = "<input name='cateNameBox' type='checkbox' value='"+categoryId+"'  id='"+categoryId+"'/>"
					+"<label for='"+categoryId+"'>"+catName+"</label>";
		return boxInfo;
	}

	@Transient
	public String getTreeNodeNameRadio() {
		String radioInfo = "<input name='cateNameBox' type='radio' value='"+categoryId+"'  id='"+categoryId+"'/>"
		+"<label for='"+categoryId+"'>"+catName+"</label>";
		return  radioInfo;
	}
	@Transient
	public String getAuditName(){
		String names = getAuditor();
		if(StringUtils.isBlank(names))
			return null;
		String[] as=names.split(",");
		return as[0];
	}
	
	private int contentNum;

	@Transient
	public int getContentNum() {
		return contentNum;
	}

	public void setContentNum(int contentNum) {
		this.contentNum = contentNum;
	}

	@Transient
	public List<Category> getSons() {
		return sons;
	}

	public void setSons(List<Category> sons) {
		this.sons = sons;
	}

	@Column(name = "SMALL_PICTURE_SIZE", length = 64)
	public String getSmallPictureSize() {
		return smallPictureSize;
	}

	public void setSmallPictureSize(String smallPictureSize) {
		this.smallPictureSize = smallPictureSize;
	}
	@Column(name = "MIDDLE_PICTURE_SIZE", length = 64)
	public String getMiddlePictureSize() {
		return middlePictureSize;
	}

	public void setMiddlePictureSize(String middlePictureSize) {
		this.middlePictureSize = middlePictureSize;
	}
	@Column(name = "BIG_PICTURE_SIZE", length = 64)
	public String getBigPictureSize() {
		return bigPictureSize;
	}

	public void setBigPictureSize(String bigPictureSize) {
		this.bigPictureSize = bigPictureSize;
	}
	@Column(name = "PIC_TYPE", length = 64)
	public String getPicType() {
		return picType;
	}

	public void setPicType(String picType) {
		this.picType = picType;
	}
	@Column(name = "CARTOON_TYPE", length = 64)
	public String getCartoonType() {
		return cartoonType;
	}

	public void setCartoonType(String cartoonType) {
		this.cartoonType = cartoonType;
	}
	@Column(name = "VIDEO_TYPE", length = 64)
	public String getVideoType() {
		return videoType;
	}

	public void setVideoType(String videoType) {
		this.videoType = videoType;
	}
	@Column(name = "SOFTWARE_TYPE", length = 64)
	public String getSoftWareType() {
		return softWareType;
	}

	public void setSoftWareType(String softWareType) {
		this.softWareType = softWareType;
	}
	@Column(name = "PICTURE_ADVICE", precision = 11, scale = 0)  
	public Long getPictureAdvice() {
		return pictureAdvice;
	}

	public void setPictureAdvice(Long pictureAdvice) {
		this.pictureAdvice = pictureAdvice;
	}
	@Column(name = "CARTOON_ADVICE", precision = 11, scale = 0)
	public Long getCartoonAdvice() {
		return cartoonAdvice;
	}

	public void setCartoonAdvice(Long cartoonAdvice) {
		this.cartoonAdvice = cartoonAdvice;
	}
	@Column(name = "VIDEO_ADVICE", precision = 11, scale = 0)
	public Long getVideoAdvice() {
		return videoAdvice;
	}

	public void setVideoAdvice(Long videoAdvice) {
		this.videoAdvice = videoAdvice;
	}
	@Column(name = "SOFTWARE_ADVICE", precision = 11, scale = 0)
	public Long getSoftwareAdvice() {
		return softwareAdvice;
	}

	public void setSoftwareAdvice(Long softwareAdvice) {
		this.softwareAdvice = softwareAdvice;
	}
	
	
	@Column(name = "CAT_SHARE", precision = 1, scale = 0)
	public Boolean getCatShare() {
		return catShare;
	}

	public void setCatShare(Boolean catShare) {
		this.catShare = catShare;
	}

	@Column(name = "AD_POSITION", length = 32)
	public String getAdPosition() {
		return adPosition;
	}

	public void setAdPosition(String adPosition) {
		this.adPosition = adPosition;
	}

	@Column(name = "IS_CATALOG_NAV", precision = 1, scale = 0)
	public Boolean getIsCatelogNav() {
		return isCatelogNav;
	}

	public void setIsCatelogNav(Boolean isCatelogNav) {
		this.isCatelogNav = isCatelogNav;
	}

	@Column(name = "CATALOG_NAV_URL", length = 32)
	public String getCatelogNavUrl() {
		return catelogNavUrl;
	}

	public void setCatelogNavUrl(String catelogNavUrl) {
		this.catelogNavUrl = catelogNavUrl;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((categoryId == null) ? 0 : categoryId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Category))
			return false;
		Category other = (Category) obj;
		if (categoryId == null) {
			if (other.categoryId != null)
				return false;
		} else if (!categoryId.equals(other.categoryId))
			return false;
		return true;
	} 
}
